Virtual memory allows execution of programs larger than physical memory by loading only required portions into RAM when needed.
Demand Paging is a memory management technique used in operating systems where pages are loaded into
main memory (RAM) only when they are actually required by the CPU. This approach helps in saving memory
space and improves system efficiency.
In demand paging, the operating system does not load the complete program into RAM at once.
Instead, it loads only those pages that are needed during execution. If a required page is not
present in main memory, a page fault occurs.
The CPU requests a specific page (for example, page P2) for execution. It first checks whether this page is available in the main memory.
The operating system checks the page table entry for page P2. If the page table indicates that P2 is not present in RAM, a page fault is generated.
After detecting the page fault, the operating system searches for page P2 in secondary memory such as the hard disk, where inactive pages are stored.
The operating system selects a free frame in main memory (for example, frame F1) and transfers page P2 from disk to this frame.
Once the page is loaded into RAM, the operating system updates the page table to reflect the new mapping between page P2 and frame F1.
After updating the page table, the CPU resumes execution and successfully accesses page P2 from main memory.
Demand paging allows the operating system to manage memory efficiently by loading pages only when they are needed. This technique plays a crucial role in virtual memory systems and improves overall system performance.
A page fault happens when the required page is not found in memory. The system then brings that page from disk into RAM.
Swapping temporarily moves processes between main memory and secondary storage to free up space for higher-priority processes.
Memory protection ensures that processes access only their allocated memory using hardware and software mechanisms.
Memory management plays a vital role in the performance and reliability of an operating system. By using techniques such as paging, segmentation, and virtual memory, the OS ensures optimal utilization of limited memory resources.